// storage
// 存储SessionStorage
export const SessionStorage = {
  set(key, val) {
    sessionStorage.setItem(key, JSON.stringify(val)); // 把数组转换为字符串  不接受数组
  },
  get(key) {
    let value;
    try {
      value = JSON.parse(sessionStorage.getItem(key));
    } catch (e) {
      console.log(e);
    }
    return value;
  },
  remove(key) {
    sessionStorage.removeItem(key)
  },
  clear() {
    sessionStorage.clear()
  }
};

export const LocalStorage = {
  set(key, val) {
    localStorage.setItem(key, JSON.stringify(val)); // 把数组转换为字符串  不接受数组
  },
  get(key) {
    let value;
    try {
      value = JSON.parse(localStorage.getItem(key));
    } catch (e) {
      value = localStorage.getItem(key);
    }
    return value;
  },
  remove(key) {
    localStorage.removeItem(key)
  },
  clear() {
    localStorage.clear()
  }
};
